Adventures of Lolo Password Generator
by: TFG (palacios_barreda@yahoo.com.mx)
-------------------------------------

To satisfy my curiosity, I decided to tackle Lolo 1 in order to figure out how the password system works.
It turned out to be extremely simple. I cooked this up in about 1 hour. Have fun.


[Adventures of Lolo Password System Format]

$750 (Alphabet Cursor X)
$751 (Alphabet Cursor Y)
$752 (Password Cursor position)

Code Table at $9467-$9480 (RAM)
There are several (over)dumps avaliable for this game, so, it's pointless to provide a ROM address.

unsigned char CodeTable[] =
{
    0xFF, 0x00, 0x01, 0x02, 0xFF, 0xFF, 0x03, 0x04, 0xFF, 0x05, 0x06, 0x07, 0x08, 0xFF, 0xFF, 0x09, 
    0x0A, 0x0B, 0xFF, 0x0C, 0xFF, 0x0D, 0xFF, 0xFF, 0x0E, 0x0F 
};


Every time you add a character to the password, the game writes 2 values to memory.

	1) The character's Pattern Table ID
	2) Corresponding code for the letter.

     	
 	|----Password-----| |------Code-------|
	|                 | |                 |
	$755 $756 $757 $758 $759 $75A $75B $75C


The password validation algorithm goes like this:

// Loop through the 4 digits of the code, if any of them
// is negative, exit the routine.
$965A LDX #$03
$965C LDA $0759,X
$965F BMI $9687
$9661 DEX
$9662 BPL $965C

// "Decode" first two characters
$9664 LDA $0759
$9667 ASL
$9668 ASL
$9669 ASL
$966A ASL
$966B ORA $075A
$966E STA $15	// Save result  

// "Decode" last two characters
$9670 LDA $075B
$9673 ASL
$9674 ASL
$9675 ASL
$9676 ASL
$9677 ORA $075C
$967A SEC
$967B SBC #$0E
$967D EOR #$FF

// Validation
$967F CMP $15	// Compare 1st result with current operation,
$9681 BNE $9687 // both numbers must be equal.
$9683 CMP #$32  // There are only 0x31 levels in the game.
$9685 BCC $9697
$9687 JSR $DC7D // Exit

[Adventures of Lolo Password Generator]

I should have reversed the original password validation algorithm to produce a better generation program.
I coded it like this to make sure there was only one possible password for each level and it turned out to
be fast enough to leave as it was.
___________________________________________________________________________________________________

#include <stdio.h>

int IsValid(int Level, signed char a, signed char b, signed char c, signed char d);

unsigned char CodesTable[] =
{
    0xFF, 0x00, 0x01, 0x02, 0xFF, 0xFF, 0x03, 0x04, 0xFF, 0x05, 0x06, 0x07, 0x08, 0xFF, 0xFF, 0x09, 
    0x0A, 0x0B, 0xFF, 0x0C, 0xFF, 0x0D, 0xFF, 0xFF, 0x0E, 0x0F 
};

int IsValid(int Level, signed char a, signed char b, signed char c, signed char d)
{
    if ((a == -1)||(b == -1)||(c == -1)||(d == -1)) return 0;

    a <<= 4;
    a |= b;

    c <<= 4;
    c |= d;
    c -= 0x0E;
    c ^= 0xFF;

    return ((a == c)&&(a == Level));
}

int main()
{
  printf("Adventures of Lolo 1 Password Generator (by TFG)\n\n");
  
  int lev, aLev = 1, bLev = 1;
  char a, b, c, d;
  
  for(lev = 0; lev <= 49; lev++){
    for(a = 0; a <= 25; a++){
      for(b = 0; b <= 25; b++){
        for(c = 0; c <= 25; c++){
          for(d = 0; d <= 25; d++){
            if (IsValid(lev, CodesTable[a], CodesTable[b], CodesTable[c], CodesTable[d]) != 0){
                        printf("(%02d-%d):%c%c%c%c ", aLev, bLev, a + 'A', b + 'A', c + 'A', d + 'A');
                        bLev++;
            }
          }
        }
      }
    }
    
    if (bLev > 5){
        printf("\n");
        bLev = 1;
        aLev++;
    }
  } 
  
  system("PAUSE");
  return 0;
}
___________________________________________________________________________________________________

Thanks to 'Parasyte' for FCEUd.
That's all.

EOF.